Multiple language using PHP


In this article, I will show you about how to create multiple language using PHP.
I hope, my sharing can help all of you and make you easy understand with this article.
you can download by click below link to see sources code Download here

1 index.php>

<pre><code>

<!--php

    include_once 'config_lan.php';

?-->

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>PHP Multi lang-Youlay</title>

        <style>

            #wrap{

                max-width: 50%;

                margin:0 auto;

                padding: 5px;

                border:solid 1px;

            }

        </style>

        <div id="wrap">

            <div class="title">PHP Multi Languages</div>

            <div class="switch_lan"><a href="index.php?lang=kh">Khmer</a> | <a href="index.php?lang=en">English</a> | <a href="index.php?lang=ch">Chinese</a></div>

            <hr>

            <div class="bordery">

                <h2><span><!--php echo $lang['name_lan'];?--></span></h2>

                <p><!--php echo $lang['description'];?--></p>

            </div>

            <hr>

            <div>

                <!--php echo $lang['copy_right'];?-->

            </div>

        </div>

</code></pre>

2. config_lan.php​

<pre><code>

<!--php

    session_start();

    if(isset($_GET['lang'])){

        $lang   =   $_GET['lang'];

        $_session['lang']   =   $lang;

        setcookie("lang",$lang, time() + (360 * 24 * 30));

    }else if(isset($_session['lang'])){

        $lang   =   $_session['lang'];

    }else if($_cookie['lang']){

        $lang   =   $_cookie['lang'];

    }else{

        $lang   =   'en';

    }

    switch($lang){

        case 'en': $lang_file   =   'lang.en.php'; break;

        case 'kh': $lang_file   =   'lang.kh.php'; break;

        case 'ch': $lang_file   =   'lang.ch.php'; break;

        default  : $lang_file   =   'lang.en.php';

    }

    include "languages/".$lang_file;

?-->

</code></pre>

3 lang.en.php

<pre><code>

<!--php

    $lang =array();

    $lang['name_lan']   =   'English language';

    $lang['copy_right'] =   'Copy right by Hong Youlay';

    $lang['description']=   '<b-->Welcome PHP Multi languages. I am very happy to share all of you about programming languages

                             that I can.

In this article, I will show you about how to create multiple language using PHP.

                             I hope, my sharing can help all of you and make you easy understand with this article.

                             Furthermore, If you do not understand or not clear you can download to see sources code or comment below for question.

                             Thanks for your sharing knowledge to your friend and read this article.';

?>

</pre></code>

Hiring Services

  • Build website
  • Develop web application
  • Graphic design
  • Maintenance and Security
  • Update website
  • Seach Egning Organization
  • Other...

My Facebook